import random

# 奖项和对应的概率
prizes = ['first', 'second', 'third', 'special']
probabilities = [0.1, 0.2, 0.3, 0.4]


def different_prize(num_prize):
    # 初始化奖项抽奖次数
    first_prize_count = 0
    second_prize_count = 0
    third_prize_count = 0
    special_prize_count = 0

    for _ in range(num_prize):
        # 使用 random.choices 根据概率选择奖项
        prize_result = random.choices(prizes, weights=probabilities, k=1)[0]

        if prize_result == 'first':
            first_prize_count += 1
        elif prize_result == 'second':
            second_prize_count += 1
        elif prize_result == 'third':
            third_prize_count += 1
        else:
            special_prize_count += 1

            # 计算每个奖项的概率
    first_prize_probability = first_prize_count / num_prize
    second_prize_probability = second_prize_count / num_prize
    third_prize_probability = third_prize_count / num_prize
    special_prize_probability = special_prize_count / num_prize

    # 返回每个奖项计算所得的概率
    return first_prize_probability, second_prize_probability, third_prize_probability, special_prize_probability


num_prize = 10000  # 抽奖的次数
first_prob, second_prob, third_prob, special_prob = different_prize(num_prize)

# 输出每个奖项的概率
print(f'first的概率: {first_prob:.4f}')
print(f'second的概率: {second_prob:.4f}')
print(f'third的概率: {third_prob:.4f}')
print(f'special的概率: {special_prob:.4f}')